/*  
 * 文件名：LoginFilter.java
 * 版权：<版权>
 * 描述：<描述>
 * 修改人：<修改人>
 * 修改时间：2017年6月29日
 * 修改单号：<修改单号>
 * 修改内容：<修改内容>
 * 
 */
package com.zzw.filter;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginFilter extends HandlerInterceptorAdapter
{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String url = request.getRequestURI();
        String contextPath = request.getContextPath();
        HttpSession session = request.getSession();
        String username = (String) session.getAttribute("username");

        if(url.indexOf("/login/index")>=0) {
            return true;
        }

        if(url.indexOf("/login/login")>=0) {
            return true;
        }


        if(username != null)
        {
            System.out.println(username);
            return true;
        }
        else {
            System.out.println("username is null");
        }
        response.sendRedirect(contextPath + "/login/index");
        return false;
    }
}
